package com.my.spring.readcode.demo;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.crypto.SecureUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.LinkedList;
import java.util.concurrent.CompletableFuture;

/**
 * @author 王存露
 * @version 1.0.0
 * @date 2021/2/1 13:51
 */
@Service
@Slf4j
public class GitHubLookupService {
    @Autowired
    private UserRepository userRepository;
    @Autowired
    private RandomNameUtils utils;

    @Async
    public void insetData(Integer z) throws InterruptedException {
        LinkedList<User> list = new LinkedList<>();
        for (int i = 0; i < 100; i++) {
            String[] strings = new String[]{"man", "woman"};
            User build = User.builder().build();
            build.setAge(RandomUtil.randomNumbers(2));
            build.setUsername(utils.getRandomName());
            build.setUserCd(RandomUtil.randomNumbers(16));
            build.setPassword(SecureUtil.md5(RandomUtil.randomNumbers(10000)));
            DateTime dateTime = RandomUtil.randomDay(0, 200);
            build.setCreateTime(dateTime);
            build.setSex(strings[RandomUtil.randomInt(0, 2)]);
            list.add(build);
        }
        userRepository.saveAll(list);
        log.info("success : {}", z);
    }
}
